package model.mediators;

import java.util.Iterator;

import model.ability.InteractiveAbility;
import model.entity.Entity;

public class UseSkillMediator extends InteractionMenuMediator {

	private class UseSkillInteractionOption extends SimpleInteractionOption {
		
		InteractiveAbility ability;
		UseSkillInteractionOption(String name, InteractiveAbility ability) {
			super(name);
			this.ability = ability;
		}
		
		public void actionPerformed() {
			ability.interactWithTarget(active, target);
		}
	}
	private Entity active;
	private Entity target;
	private InteractiveMediator parentMediator;
	
	/**
	 * @param active
	 * @param target
	 */
	public UseSkillMediator(Entity active, Entity target, InteractiveMediator parentMediator) {
		this.active = active;
		this.target = target;
		this.parentMediator = parentMediator;
		init();
	}

	public void init() {
		WindowedInteraction window = new WindowedInteraction("Use Skill Menu", this);
		
		Iterator<InteractiveAbility> abilityIterator = active.interactiveAbilityListIterator();
		
		while (abilityIterator.hasNext()) {
			InteractiveAbility ability = abilityIterator.next();
			window.addButton(new UseSkillInteractionOption(ability.getName(), ability));
		}
		
		window.createWindow();
	}
	
	public void exit() {
		parentMediator.show();
	}

}
